package com.xl.sst.utill;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.DeserializationContext;
import org.codehaus.jackson.map.JsonDeserializer;

public class DateJsonDeserializer extends JsonDeserializer<Date>{
	//把json日期字符串转换为日期类型   用@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")也可以
	 public static final SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
	@Override
	public Date deserialize(JsonParser jsonParser,DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
		 try  
	        {  
	            return format.parse(jsonParser.getText());  
	        }  
	        catch(Exception e)  
	        {  
	            System.out.println(e.getMessage());  
	            throw new RuntimeException(e);  
	        }   
	}

}
